﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ENT;
using System.Data.SqlClient;
using System.Data;

namespace DAT
{
    public class datSinhVien
    {
        SqlCommand cmd;
        SqlDataReader dr;
        public List<entSinhVien> getSinhVienDangNhap(entSinhVien sv)
        {
            string constr = System.Configuration.ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
            SqlConnection sqlConnection = new SqlConnection(constr);
            sqlConnection.Open();
            cmd = new SqlCommand("sp_SinhVienDangNhap", sqlConnection);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter[] sqla=new SqlParameter[2];
            sqla[0] = new SqlParameter("MaSinhVien", DbType.String);
            sqla[1] = new SqlParameter("MatKhau", DbType.String);

            sqla[0].Value = sv.MaSinhVien;
            sqla[1].Value = sv.MatKhau;
            cmd.Parameters.AddRange(sqla);

            dr = cmd.ExecuteReader();
            entSinhVien entsv = new entSinhVien();
            List<entSinhVien> lst=new List<entSinhVien>();
            while (dr.Read())
            {
                entsv = new entSinhVien();
                entsv.MaSinhVien = dr["MaSinhVien"].ToString();
                entsv.Ten = dr["Hoten"].ToString();
                lst.Add(entsv);
            }
            dr.Close();
            sqlConnection.Close();
            return lst;
        }
        public entSinhVien getSinhVienByMaSV(String masv)
        {
            string constr = System.Configuration.ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
            SqlConnection sqlConnection = new SqlConnection(constr);
            sqlConnection.Open();
            cmd = new SqlCommand("sp_SinhVienGetByMaSV", sqlConnection);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter[] sqla = new SqlParameter[1];
            sqla[0] = new SqlParameter("masinhvien", DbType.String);
            sqla[0].Value = masv;

            cmd.Parameters.AddRange(sqla);

            dr = cmd.ExecuteReader();
            entSinhVien entSV = new entSinhVien();
            if (dr.Read())
            {
                entSV.MaSinhVien=dr["masinhvien"].ToString();
                entSV.Ten=dr["hoten"].ToString();
                entSV.MaLop=dr["malop"].ToString();
                entSV.NgaySinh=dr["ngaysinh"].ToString();
                entSV.MatKhau = dr["MatKhau"].ToString();
            }
            dr.Close();
            sqlConnection.Close();
            return entSV;

        }
        public void updatemk(entSinhVien entSV)

        {
            string constr = System.Configuration.ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
            SqlConnection sqlConnection = new SqlConnection(constr);
            sqlConnection.Open();
            cmd = new SqlCommand("sp_SinhVienUpdateMK", sqlConnection);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter[] sqla = new SqlParameter[1];
            sqla[0] = new SqlParameter("masinhvien", DbType.String);
            sqla[0].Value = entSV.MaSinhVien;
            cmd.Parameters.AddRange(sqla);
            cmd.ExecuteNonQuery();
            sqlConnection.Close();
        }
    }
}
